package com.ssyc.gsk_master.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ssyc.common.adapter.CommonAdapter;
import com.ssyc.common.adapter.ViewHolder;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.gsk_master.R;
import com.ssyc.gsk_master.activity.MasterSkinListActivity;
import com.ssyc.gsk_master.bean.RedTemplateInfo;

import java.util.List;

/**
 * 红包皮肤的适配器
 */

public class RedTemplateAdapter extends CommonAdapter<RedTemplateInfo.SkinsBean> {
    private Context context;
    private int screenWidth;

    private LinearLayout.LayoutParams lp;

    public RedTemplateAdapter(Context context, List<RedTemplateInfo.SkinsBean> datas, int layoutId, int screenWidth) {
        super(context, datas, layoutId);
        this.context = context;
        this.screenWidth = screenWidth;
        int width = (this.screenWidth - 8 * 2 - 16) / 2;
        int height = width * 3 / 2;
        lp = new LinearLayout.LayoutParams(width, height);
    }

    @Override
    public void convert(ViewHolder holder, final RedTemplateInfo.SkinsBean skinsBean) {
        LinearLayout llOut = holder.getView(R.id.ll_out);
        llOut.setLayoutParams(lp);
        //图片
        ImageView lv = holder.getView(R.id.lv);
//        Picasso.with(mContext).load(skinsBean.getViewimg()).error(R.drawable.redpackage).into(lv);

        ImageUtil.displayImage(mContext,lv,skinsBean.getViewimg(),R.drawable.redpackage);
//        Picasso.with(this)().load(skinsBean.getHeadimg()).error(R.drawable.defaultimage).into(lv);
        
        //名称
        TextView tv = holder.getView(R.id.tv_name);
        tv.setText(skinsBean.getTitle());

        //设置点击事件
        llOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到皮肤列表界面
                Intent intent = new Intent(context, MasterSkinListActivity.class);
                intent.putExtra("top", skinsBean.getHeadimg());
                intent.putExtra("center", skinsBean.getBodyimg());
                intent.putExtra("bottom", skinsBean.getPacketimg());
                intent.putExtra("themeId", skinsBean.getId()+"");
                context.startActivity(intent);
            }
        });
    }
}
